import React, { useEffect, useState } from "react";
import lessModule from "./index.module.less"
import { Outlet, useLocation, useNavigate } from "react-router-dom";
import HomePage_HeaderMenuComponent from "./component/headerMenu";
import { $PowerSetting } from "../../common/utils";
import { $hash } from "../../network/request";



// 主页
const HomePage: React.FC = () => {
const location = useLocation()
const navigate = useNavigate()
// 监听权限路由
const change_powerRouter=()=>{
  const basePowerRouterList=["/home/systemSettings/defaultConfiguration"]
  const superPowerRouterList=["/home/systemSettings/reviewWorkOrder"]
  basePowerRouterList.includes(location.pathname) && !$PowerSetting()["basePower"] &&  navigate("login")
  superPowerRouterList.includes(location.pathname) && !$PowerSetting()["superPower"] &&  navigate("login")
}
  useEffect(()=>{
    change_powerRouter()

  },[location])

  useEffect(()=>{

    $hash.listen((data) => {
      data["location"]["pathname"] === "/login" && navigate(data["location"]["pathname"]) //排除 账号管理页面
  })
  },[])
  return (

    <div className={lessModule["homePage"]}>
      <HomePage_HeaderMenuComponent />
      <main className={lessModule["homePage-main"]}>
        <Outlet />
      </main>

    </div>
  )
}

export default HomePage